import { writable, derived } from 'svelte/store';

// 计数器模块的状态
const state = writable({
  count: 0,
});

// 计数器模块的 getters
const getters = {
  doubleCount: derived(state, ($state) => $state.count * 2),
};

// 计数器模块的 mutations
const mutations = {
  increment(state) {
    state.count += 1;
  },
};

// 计数器模块的 actions
const actions = {
  increment() {
    state.update((currentState) => {
      mutations.increment(currentState);
      return currentState;
    });
  },
};

export const counterModule = {
  state,
  getters,
  actions,
};